<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<%@ taglib prefix="fn" uri="/WEB-INF/tlds/fn.tld"%>
<%@ taglib prefix="fmt" uri="/WEB-INF/tlds/fmt.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>货品列表</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${Plugins}/jquery/jquery-1.4.4.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/utils.js" type="text/javascript"></script>
<style type="text/css">
#searchbar{
	margin-bottom: 10px;
}
.navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search{
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
</style>
</head>
<body style="padding:6px; overflow:hidden;">
<div id="">
	<div class="navbar"><span>您当前的位置：基本信息管理 &gt;让利比例设置 </span></div>
	<br/>
	<table width="100%" cellpadding="0" cellspacing="0" class="l-table-edit" style="TABLE-LAYOUT: fixed" >
		<input type="hidden" id="commoNo" name="commoNo" value="${CommodityVo1.commoNo}">
		<input type="hidden" id="commoName" name="commoName" value="${CommodityVo1.commoName}">
	    <tr height="15">
	     <td align="right" class="l-table-edit-td">商品编码:</td>
	        <td align="left" class="l-table-edit-td">${CommodityVo1.commoNo}</td>
	        <td align="right" class="l-table-edit-td">商品名称:</td>
	        <td align="left" class="l-table-edit-td">${CommodityVo1.commoName}</td>
	       
	    </tr>
	    <tr height="15"></tr>
	</table>
	<br/>
	

</div>
<div id="maingrid6" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- g data total ttt -->
</div>
<form name="form1" method="post" action="c_profits.do" id="form1" />
<script type="text/javascript">
	
    var basePath='${BasePath}';
	var grid6 = null;
    var profitsData = {"Rows": ${rows}, "Total": ${total}};
    var datalist = new Array();
    $(function () {
    	grid6 = $("#maingrid6").ligerGrid({
  	      columns: [
                    { display: '货品编码', name: 'prodNo'},
  	                { display: '商品名称', name: 'commoName', render: function(rowdata, rowindex, value){
  	                	return "${fn:escapeXml(CommodityVo1.commoName)}";
  	                }},
  	               { display: '让利比例',name:'profits', profits: false, render: function (rowdata, rowindex, value){
  	            	 var profits = "";
  	            	 if(rowdata.profits != null) profits = rowdata.profits;
  	            	 var profitsList =$.parseJSON('${profitsList}');
  	            	 if(profitsList != null){
  	            		for ( var i in profitsList) {
  	  	            		if(profitsList[i].productCode ==  rowdata.prodNo){
  	  	            			profits = profitsList[i].profits;
  	  	            		}
  						}
  	            	 }
  	            	 
  	            	var  text = "<input onblur='updateProfits("+rowindex+")' value='"+ profits +"'  name='profits' id='profits" + rowdata.__id + "'   class='l-textarea' style='width: 50px;' />&nbsp;%";
  	                return text;
  	            	},
  	             },
  	                ], 
  	                width: '100%',
  	                height: '100%',
  	              data: $.extend(true,{},profitsData),
  		});
    	
    	
        for ( var i in grid6.getData()) {
        	var prodNo = grid6.getData()[i].prodNo;
        	var commoName = "${fn:escapeXml(CommodityVo1.commoName)}";
        	datalist.push({prodNo:prodNo,commoName:commoName});
		};
    })
    
    
    function updateProfits(rowindex) {
    	datalist[rowindex].profits = $("input[name=profits]").eq(rowindex).val();
	}
    
    var isSuccess = null;
	//保存已选择的货品供应商设置信息
	  function addProfitsData() {
		  url= basePath+"/base/ProfitsController/c_profits.do";
		  var profitlist =JSON.stringify(datalist);
			$.post(url,
				{profitlist : profitlist,
				commodityCode:$("#commoNo").val(),
				commodityName:$("#commoName").val()},	
				function(data) {
				isSuccess = data;
				if(data == "success"){
					var s =window.parent.$.ligerDialog.success("设置成功！","提示",function () {
						parent.window.location.href = '../../base/ProfitsController/toCommodityList.do';
    	        	});
				}else{
					window.parent.$.ligerDialog.error("设置失败！");
				};
			});
		}
    
	
	

</script>


</body>
</html>